/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package officeboost.domain;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import officeboost.domain.equip_venue.Equipment;
import officeboost.domain.equip_venue.Venue;
import officeboost.entity.Group;
import officeboost.entity.User;

/**
 *
 * @author sorra
 */
@Singleton
public class TestMgr {
    @EJB
    private DataImportMgr dim;
    @EJB
    private PersonService personService;
    @EJB
    private GroupService groupService;
    @EJB
    private EquipmentService equipmentService;
    @EJB
    private VenueService venueService;
    @EJB
    private LogMgr logger;
    private boolean done = false;
    
//    public void importUsers(FileReader fr) {
//	dim.importUsers(fr);
//    }

    public void setup() {
	if (done) {
	    return;
	}
	
        setupMany();

//	personService.testSetup();
//	groupService.testSetup();
//	equipmentService.testSetup();
        logger.log("Test Setup!");
        done = true;
    }

    private void setupMany() {
	List<User> list1 = new ArrayList<User>();
	for (int i = 0; i < 5; i++) {
	    User test = new User();
	    test.setId("student" + i);
	    test.setName("WangKail" + i);
	    test.setPassword("123");
	    personService.persist(test);
	    list1.add(test);
	}
	List<User> list2 = new ArrayList<User>();
	for (int i = 5; i < 8; i++) {
	    User test = new User();
	    test.setId("student" + i);
	    test.setName("WangKail" + i);
	    test.setPassword("123");
	    personService.persist(test);
	    list2.add(test);
	}
	List<User> list3 = new ArrayList<User>();
	for (int i = 8; i < 10; i++) {
	    User test = new User();
	    test.setId("student" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list3.add(test);
	}
	List<User> list4 = new ArrayList<User>();
	for (int i = 10; i < 12; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list4.add(test);
	}
	List<User> list5 = new ArrayList<User>();
	for (int i = 12; i < 14; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list5.add(test);
	}
	List<User> list6 = new ArrayList<User>();
	for (int i = 14; i < 16; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list6.add(test);
	}
	List<User> list7 = new ArrayList<User>();
	for (int i = 16; i < 18; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list7.add(test);
	}
	List<User> list8 = new ArrayList<User>();
	for (int i = 18; i < 20; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list8.add(test);
	}
	List<User> list9 = new ArrayList<User>();
	for (int i = 20; i < 22; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list9.add(test);
	}
	List<User> list10 = new ArrayList<User>();
	for (int i = 22; i < 24; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list10.add(test);
	}
	List<User> list11 = new ArrayList<User>();
	for (int i = 24; i < 26; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list11.add(test);
	}
	List<User> list12 = new ArrayList<User>();
	for (int i = 26; i < 28; i++) {
	    User test = new User();
	    test.setId("teacher" + i);
	    test.setName("WangKail" + i);
	    personService.persist(test);
	    list12.add(test);
	}
        User test = new User();
	test.setId("admin");
	test.setName("WangKail");
	personService.persist(test);


	Group g1 = new Group();
	g1.setName("student");
	g1.setUsers(list1);
	groupService.persist(g1);
	Group g2 = new Group();
	g2.setUsers(list2);
	g2.setName("worker");
	groupService.persist(g2);
	Group g3 = new Group();
	g3.setName("admin");
	g3.setUsers(list3);
	groupService.persist(g3);
	Group g4 = new Group();
	g4.setName("teacher");
	g4.setUsers(list4);
	groupService.persist(g4);
	Group g5 = new Group();
	g5.setName("student_office");
	g5.setUsers(list5);
	groupService.persist(g5);
	Group g6 = new Group();
	g6.setName("president");
	g6.setUsers(list6);
	groupService.persist(g6);
	Group g7 = new Group();
	g7.setName("education_office");
	g7.setUsers(list7);
	groupService.persist(g7);
	Group g8 = new Group();
	g8.setName("class_education_office");
	g8.setUsers(list8);
	groupService.persist(g8);
	Group g9 = new Group();
	g9.setName("department_leader");
	g9.setUsers(list9);
	groupService.persist(g9);
	Group g10 = new Group();
	g10.setName("school");
	g10.setUsers(list10);
	groupService.persist(g10);
	Group g11 = new Group();
	g11.setName("college_edu_office");
	g11.setUsers(list11);
	groupService.persist(g11);
	Group g12 = new Group();
	g12.setName("college_office");
	g12.setUsers(list12);
	groupService.persist(g12);
	for(int i=12 ; i<28 ; i++)
	{
	    groupService.addUserToGroup("teacher"+i,"teacher");
	}
	
	Equipment e1 = new Equipment();
	e1.setId("1");
	e1.setName("投影仪A");
	e1.setTheUsage("教学");
	e1.setStatus("availiable");
	Equipment e2 = new Equipment();
	e2.setId("2");
	e2.setName("手提电脑A");
	e2.setTheUsage("教学,会议");
	e2.setStatus("availiable");
	Equipment e3 = new Equipment();
	e3.setId("3");
	e3.setName("打印机A");
	e3.setTheUsage("办公");
	e3.setStatus("availiable");
	Equipment e4 = new Equipment();
	e4.setId("4");
	e4.setName("空调遥控器A");
	e4.setTheUsage("后勤");
	e4.setStatus("availiable");
	equipmentService.persist(e1);
	equipmentService.persist(e2);
	equipmentService.persist(e3);
	equipmentService.persist(e4);
	Equipment e5 = new Equipment();
	e5.setId("5");
	e5.setName("投影仪B");
	e5.setTheUsage("教学");
	e5.setStatus("availiable");
	equipmentService.persist(e5);
	Equipment e6 = new Equipment();
	e6.setId("6");
	e6.setName("显示器A");
	e6.setTheUsage("教学,办公");
	e6.setStatus("availiable");
	equipmentService.persist(e6);
	Equipment e7 = new Equipment();
	e7.setId("7");
	e7.setName("VGA线A");
        e7.setTheUsage("教学,会议");
        e7.setStatus("availiable");
        equipmentService.persist(e7);
        
        Venue v1 = new Venue();
        v1.setId("441");
        v1.setTankage("30");
        v1.setTheUsage("会议");
        v1.setState("available");
        Venue v2 = new Venue();
        v2.setId("434");
        v2.setTankage("100");
        v2.setTheUsage("会议,教学，讲座");
        v2.setState("available");
        Venue v3 = new Venue();
        v3.setId("334");
        v3.setTankage("100");
        v3.setTheUsage("会议，教学，讲座");
        v3.setState("available");
        Venue v4 = new Venue();
        v4.setId("417");
        v4.setTankage("50");
        v4.setTheUsage("会议，讲座");
        v4.setState("available");
        venueService.persist(v1);
        venueService.persist(v2);
        venueService.persist(v3);
        venueService.persist(v4);
        Venue v5 = new Venue();
        v5.setId("447");
        v5.setTankage("10");
        v5.setTheUsage("会议");
        v5.setState("available");
        venueService.persist(v5);
        Venue v6 = new Venue();
        v6.setId("418");
        v6.setTankage("50");
        v6.setTheUsage("教学");
        v6.setState("available");
        venueService.persist(v6);
        Venue v7 = new Venue();
        v7.setId("301");
        v7.setTankage("300");
        v7.setTheUsage("会议，讲座");
        v7.setState("available");
        venueService.persist(v7);	
    }
    
}
